﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using InfoJetSoft.Service.Entity;

//CID 0755 //2011.01.14 //Begin
namespace InfoJetSoft.Service.Util
{
    class XPathFunction : IXsltContextFunction
    {
        private Form form = null;
        private string prefix = null;
        private string name = null;
        private int maxArgs;
        private int minArgs;
        private XPathResultType[] argTypes;
        private XPathResultType returnType;

        public XPathFunction(Form formParam, string prefixParam, string nameParam, int maxArgsParam, int minArgsParam, XPathResultType[] argTypesParam, XPathResultType returnTypeParam)
        {
            this.form = formParam;
            this.prefix = prefixParam;
            this.name = nameParam;
            this.maxArgs = maxArgsParam;
            this.minArgs = minArgsParam;
            this.argTypes = argTypesParam;
            this.returnType = returnTypeParam;
        }

        #region IXsltContextFunction Members

        public XPathResultType[] ArgTypes
        {
            get { return this.argTypes; }
        }

        public int Maxargs
        {
            get { return this.maxArgs; }
        }

        public int Minargs
        {
            get { return this.minArgs; }
        }

        public XPathResultType ReturnType
        {
            get { return this.returnType; }
        }

        public object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
        {
            string uri = this.form.Manifest.NsResolver.LookupNamespace(prefix);
            if (uri != null)
            {
                IExtensionFunctions extFuncs = this.form.XsltArgList.GetExtensionObject(uri) as IExtensionFunctions;
                if (extFuncs != null)
                {
                    return extFuncs.InvokeFunction(this.prefix, this.name, xsltContext, args, docContext);
                }
            }
            return null;
        }
        #endregion

    }
}
//CID 0755 //2011.01.14 //End
